﻿using Xejen.Communication.Configuration;
using Xejen.Communication.Ftp.Abstract;
using Xejen.Communication.Ftp.Communicator;
using Xejen.Communication.Ftp.Configuration;
using Xejen.Hosting;
using Xejen.Hosting.Extensions;
using Xejen.Logger;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Communication.Ftp.Extensions
{
    /// <inheritdoc cref="IFtpCommunicatorBuilder"/>的实现
    internal sealed class FtpCommunicatorBuilder : CommunicatorBuilder<IFtpCommunicatorBuilder>, IFtpCommunicatorBuilder
    {
        private readonly ILogger _logger;
        private readonly FtpConfig _ftpConfig = new FtpConfig();

        /// <inheritdoc cref="FtpCommunicatorBuilder"/>
        /// <param name="host"><inheritdoc cref="IAppHost" path="/summary"/></param>
        public FtpCommunicatorBuilder(IAppHost host) : base(host)
        {
           _logger = LoggerManager.CreateLogger(typeof(FtpCommunicatorBuilder));
        }

        /// <inheritdoc/>
        public IFtpCommunicatorBuilder ConfigureFtpConfiguration(Action<FtpConfig> configure)
        {
            Configuration.Bind(nameof(FtpConfig), _ftpConfig);

            configure?.Invoke(_ftpConfig);

            this.ConfigureServices((services) =>
            {
                services.AddSingleton(_ftpConfig);
            });

            _logger.LogInformation($"完成{nameof(FtpConfig)}配置：{{@value}}", _ftpConfig);

            return this;
        }
    }
}
